package com.xinzhi.yjyz.comtroller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xinzhi.entity.Keeper;
import com.xinzhi.entity.Retention;
import com.xinzhi.util.R;
import com.xinzhi.yjyz.mapper.RetentionMapper;
import com.xinzhi.yjyz.service.IRetentionService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class RetentionController {
    @Resource
    private RetentionMapper retentionMapper;
    @Resource
    private IRetentionService iRetentionService;

    @PostMapping("/insertRetention")
    @ResponseBody
    public R insert(Retention retention){
        Retention retention1=new Retention();
       retention1.setZl_name(retention.getZl_name());
       retention1.setZl_phone(retention.getZl_phone());
       retention1.setZl_waybill(retention.getZl_waybill());
       retention1.setZl_kdname(retention.getZl_kdname());
       retention1.setZl_faddress(retention.getZl_faddress());
       retention1.setZl_saddress(retention.getZl_saddress());
       retention1.setZl_cause(retention.getZl_cause());
        retentionMapper.insert(retention1);
        return new R(200,"增加成功",retention);
    }
    @PostMapping ("/selretention")
    public R select() {
        List<Retention> retentions = retentionMapper.selectList(null);
        retentions.forEach(System.out::println);
        return new R(200, "查询成功",retentionMapper.selectList(null));
    }
    @GetMapping ("/insname/{name}")
    public R insertname(@PathVariable String name){
        QueryWrapper<Retention> queryWrapper=new QueryWrapper<>();
        queryWrapper.isNotNull(name);
        int delete= retentionMapper.delete(queryWrapper);
        return new R(200,"删除成功",delete);
    }
    @GetMapping ("/insphone/{phone}")
    public R insertphone(@PathVariable String phone) {
        QueryWrapper<Retention> queryWrapper = new QueryWrapper<>();
        queryWrapper.isNotNull(phone);
        int delete = retentionMapper.delete(queryWrapper);
        return new R(200, "删除成功", delete);
    }
}
